<template>
  <el-form ref="form" :rules="rules" style="padding-top: 10px;" :model="form" label-width="80px">
    <el-form-item label="材料编码" prop="code">
      <el-input v-model="form.code" />
    </el-form-item>
    <el-form-item label="材料名称" prop="name">
      <el-input v-model="form.name" />
    </el-form-item>
    <el-form-item label="规格" prop="specification">
      <el-input v-model="form.specification" />
    </el-form-item>
    <el-form-item label="单位" prop="unit">
      <el-input v-model="form.unit" />
    </el-form-item>
    <el-form-item label="类型" prop="type">
      <el-select v-model="form.type" placeholder="请选择">
        <el-option label="消耗材" value="1" />
        <el-option label="周转材" value="2" />
        <el-option label="设备" value="3" />
      </el-select>
    </el-form-item>
    <el-form-item label="禁用" prop="enable">
      <el-checkbox v-model="form.enable" />
    </el-form-item>
    <el-form-item label="说明" prop="description">
      <el-input v-model="form.description" />
    </el-form-item>
  </el-form>
</template>

<script>
import { sexTypes, bloodTypes } from '@/utils/dicData'
export default {
  name: 'AddMaterial',
  props: {
    data: {
      type: Object,
      default() {
        return {}
      }
    },
    type: {
      type: String,
      default: 'add'
    }
  },
  data() {
    return {
      sexTypes,
      bloodTypes,
      form: {
        'code': '',
        'description': '',
        'enable': false,
        'id': '',
        'materialDirectoryId': '',
        'name': '',
        'specification': '',
        'type': 0,
        'unit': ''
      },
      rules: {
        name: [
          { required: true, message: '请输入材料名称', trigger: 'change' }
        ]
      }
    }
  },
  watch: {
    data: {
      handler(newData, oldData) {
        Object.keys(this.form).forEach(key => {
          const val = newData[key]
          this.form[key] = val
        })
      },
      deep: true,
      immediate: true
    }
  },
  mounted() {
  },
  methods: {
    validateForm(fn) {
      this.$refs.form.validate((valid) => {
        fn(valid)
      })
    },
    resetForm() {
      this.$refs.form.resetFields()
    }

  }
}
</script>

<style lang="scss" scoped>

</style>
